package com.ruoyi.intelligence.chat.aliyun;

import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.models.QwenParam;
import com.alibaba.dashscope.common.History;
import com.alibaba.dashscope.common.HistoryManager;
import com.alibaba.dashscope.common.ResultCallback;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.aigc.generation.Generation;
import java.util.concurrent.Semaphore;

/**
 * @Author: wxj
 * 智海三乐教育大模型
 * @Date: 2023/11/23
 */
public class ZHSLFactory {

    private static final String model="qwen-7b-chat-v1";
    public static void qwenQuickStart()
        throws NoApiKeyException, ApiException, InputRequiredException {
        Generation gen = new Generation();
        String prompt="请简要介绍一下浙江大学";
        HistoryManager historyManager = new HistoryManager(10);
        History his = History.builder()
            .bot("我当然知道浙江大学")
            .user("你知道浙江大学么")
            .user("你知道浙江大学么")
            .build();
        historyManager.add(his);
        QwenParam param = QwenParam
            .builder()
            .model(model)
            .prompt(prompt)
            .apiKey("sk-010ca67d2a35422cba1f0fe9d214dd96")
            .history(historyManager.get())
            .topP(0.8)
            .build();
        GenerationResult result = gen.call(param);
        System.out.println(result.getOutput().getText());
    }

    public static void main(String[] args) {
        try {
            qwenQuickStart();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(String.format("Exception %s", e.getMessage()));
        }
        System.exit(0);
    }
}
